package javaseof10day.day7.am;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBuitls {

//需要下载 MySQL驱动程序 mysql-connector-java-5.x-bin.jar
	static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
	static final String DB_URL = "jdbc:mysql://localhost:3306/mblog?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false";

	private static java.sql.Connection conn = null;
	private static java.sql.Statement stmt = null;

	static final String USER = "root";
	static final String PASS = "root";

	public static java.sql.Statement getconn() throws ClassNotFoundException, SQLException {

		// 注册 JDBC 驱动
		Class.forName(JDBC_DRIVER);

		// 打开链接
		System.out.println("连接数据库...");
		conn = DriverManager.getConnection(DB_URL, USER, PASS);

		// 执行查询
		System.out.println(" 实例化Statement对象...");

		return conn.createStatement();

	}

	public static void connclose() throws SQLException {

		if (stmt != null) {
			stmt.close();

		}

		if (conn != null) {
			conn.close();
		}

	}

}
